﻿using System.Drawing;
using System.Windows.Forms;


namespace FXnaGis
{


    public class FPanMF:FMapFunction
    {


        public FPanMF(FMapFrame frame)
            : base(frame)
        {


            this._enabled = false;

            



        
        }


        #region Private Variables

        private Point _dragStart;
        private bool _isDragging;
       
        private Rectangle _source;


        bool _isMoved=false;



        #endregion


        protected override void OnActivate()
        {
            base.OnActivate();

            //在这里尝试替换鼠标状态

            this._geoMapFrame.Parent.Cursor = Cursors.Hand;



        }

        protected override void OnDeactivate()
        {
            base.OnDeactivate();

            this._geoMapFrame.Parent.Cursor = Cursors.Default;
        }



        protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
        {

            if (e.Button == MouseButtons.Left)
            {
                //PreventBackBuffer = true;
                _isDragging = true;
                _dragStart = e.Location;
                _source = this._geoMapFrame.View;


              
            }


            base.OnMouseDown(e);
        }

        protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
        {

            if (_isDragging)
            {
                Point diff = new Point { X = _dragStart.X - e.X, Y = _dragStart.Y - e.Y };



                this._geoMapFrame.View = new Rectangle(_source.X + diff.X, _source.Y + diff.Y, _source.Width,
                                                    _source.Height);

                //要求重绘
                this._geoMapFrame.Parent.Invalidate();

                this._isMoved = true;

            }

            base.OnMouseMove(e);
        }


        protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
        {

            if (e.Button == MouseButtons.Left && _isDragging)
            {


                _isDragging = false;

                //判断是否需要变更视图
                if (_isMoved)
                {

                    this._geoMapFrame.ResetExtents();

                    this._isMoved = false;
                }
                
             
               
                
            }


            base.OnMouseUp(e);
        }






    }
}
